package com.zgs.mall.search.controller;

import com.zgs.common.exception.BizCodeEnum;
import com.zgs.common.to.es.SkuEsModel;
import com.zgs.common.utils.R;
import com.zgs.mall.search.service.ElasticSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("search/elasticSave")
public class ElasticSaveController {
    @Autowired
    private ElasticSaveService elasticSaveService;
    //上架商品
    @PostMapping("productStatusUp")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        Boolean b=false;
        try{
             b = elasticSaveService.productStatusUp(skuEsModels);
        }catch (Exception e){
            log.error("商品上架失败,原因:{}",e);
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if(!b){
            return R.ok();
        }else{
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }

    }
}
